<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="javax.servlet.http.Cookie" %>
<%@ include file="include.jsp" %>  
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<title>二维码签到系统学生手机端</title>
</head>
<style type="text/css">
	body{
		background-image: url(https://i.loli.net/2021/06/20/KufQyYRiMgPc4Ij.jpg);
		background-size:cover;
		background-attachment: fixed;
	}
</style>
<body>
		<%
			String randomUUID=request.getParameter("randomUUID");
			Cookie[] cc = request.getCookies();//获取客户端本地的cookie数据
			boolean flag=false;//表示没有登录
			String sphone="";//学生电话号码
			String sno="";//学生在数据库的编号
			for(Cookie c:cc){
				if(c.getName().equals("islogin")){
					if(c.getValue().equals("true")){
						flag=true;
					}
				}
				
				if(c.getName().equals("sphone")){
					sphone=c.getValue();
				}
				
				if(c.getName().equals("sno")){
					sno=c.getValue();
				}
			}
		 %>
<nav class="navbar navbar-default navbar-fixed-top">
			<div class="container">
				<div class="navbar-header">
					<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
				        <span class="sr-only">Toggle navigation</span>
				        <span class="icon-bar"></span>
				        <span class="icon-bar"></span>
				        <span class="icon-bar"></span>
				    </button>
					<a class="navbar-brand" href="#">齐鲁工业大学</a>
				</div>
				<!-- Collect the nav links, forms, and other content for toggling -->
				<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

					<ul class="nav navbar-nav navbar-right">
						<%
							if(flag==true){
						%>
							<li>
								<a href="#"> <span class="glyphicon glyphicon-user"> </span> 欢迎:<%= sphone %></a>
							</li>
							<li>
							    <a href="studentLogin.jsp" id="adoOut"><span class="glyphicon glyphicon-log-out"> </span> 安全退出</a>
						    </li>
						<%		
							}else{
							
						%>
							<li>
								<a href="studentLogin.jsp"> <span class="glyphicon glyphicon-user"> </span> 登陆</a>
							</li>
						<%	
							}
						 %>
					 

					</ul>
			</div>	
		</div>
</nav>
		


<div class=" " style="margin-top: 200px;">
<h1 align="top">二维码签到</h1>
	<div class="container">
		<h3 id="serverMsg"></h3>   
		
	</div>

</div>

<div id="btnDiv"> 
	<div class="container">
		<input type="button" id="btn1" class="btn btn-block btn-lg btn-danger" value="签到" />
	</div>
</div>

<div id="div_qd" style="display: none;">
			
			<div class="container">
				<h3 id="tihsiMsg"></h3>
				<div align="center">
					
					<img id="stateImg" class="img-responsive" src="" />
				</div>
				<br />
				<input type="button" name="" class="btn btn-danger btn-block" id="" value="返回主菜单" onclick="showHomePage('div_qd')" />
				
				<div style="margin-top: 55px;"></div>
				
			</div>
</div>
<script type="text/javascript">
function showHomePage(div_id){
	$("#"+div_id).fadeOut(100,function(){
		$("#btnDiv").fadeIn(500);
	});
}

//为按钮增加点击的事件处理
$("#btn1").click(function() {
		
			stuQDFun();

});


//签到 方法

function stuQDFun(){
	//判断用户是否登陆了，如果登陆了才可以签到，否则提示 请先登录
	
	<%
			Cookie cks[]= request.getCookies();
		String val=null;
		for(Cookie c:cks){
			if(c.getName().equals("islogin")){
				val=c.getValue();
			}
		}
	
	%>
	
	var islogin='<%=val%>';
		if(islogin=='null'){
		alert('登录才可以签到');
		return ;  
	}
	$("#btnDiv").fadeOut(500, function() {
		$("#div_qd").fadeIn(500,function(){  
			 
			 //发送ajax签到自己
			 $.ajax({     
				     type : "POST", //提交方式
				     url : "${CTX_PATH}/servlet/QDServlet",//路径
				     data:{
				     	"sno":'<%=sno%>'  , 
				     	"uuid":'<%=randomUUID%>' 
				     },
				     success : function(result) {//返回数据根据结果进行相应的处理
				    	 $("#tihsiMsg").html(result);
				     		//返回的完整数据具体是是什么 需要 断点调试
	 			      		 /*	alert(result.length);
	 			      		 if(result.length != 8 ){
	 			      		 	//显示错误的图片
	 			      		 	$("#stateImg").attr("src",'${CTX_PATH}/img/x.jpg');
	 			      		 }else{
	 			      		 	$("#stateImg").attr("src",'${CTX_PATH}/img/dui.jpg');
	 			      		 }*/
	 			     } 
			    });
		});
	});
}
$("#btn2").click(function() {
	var islogin='<%=val%>';
		if(islogin=='null'){
		alert('登录才可以签到');
		return ;  
	}
	
	$("#btnDiv").fadeOut(500, function() {
		
		//为老师这个 选择框 赋值 /servlet/GetClassTeacherDataServlet
			$.ajax({        
			     type : "POST", //提交方式
			     url : "${CTX_PATH}/servlet/GetClassTeacherDataServlet",//路径
			     data:{   
			     	 "sno":'<%=sno%>'   
				     },
			     dataType:"json",  
			     success : function(result) {//返回数据根据结果进行相应的处理       
 			       	//
 			      	$.each(result,function(inx,iteam){
 			      		 var dddata="<option value='"+iteam.tid+"'> "+iteam.tname+" </option>";
 			      		
 			      		 $("#teacherData").append(dddata);   
 			      	});
 			     }
		  });      
		
		$("#div_sqqj").fadeIn(500);
	});
});

$("#btn3").click(function() {
	$("#btnDiv").fadeOut(500, function() {
		
		//访问后台获取数据
		$.ajax({        
			     type : "POST", //提交方式
			     url : "${CTX_PATH}/servlet/GetStudentQDRecordServlet",//路径
			     data:{
			     	 "stuno":'<%=sno%>'   
				     },
			     dataType:"json",  
			     success : function(result) {//返回数据根据结果进行相应的处理    
 			      	$.each(result,function(index,item){    
 			      	
 			      		 //将之间的数据先删除
 			      		 // 找到dom结构 删除#tableData 的后面的兄弟元素
 			      		 $("#tableData").next("tr").remove(); 
    		    
 			      	   	var ss;
			      		   if(item.cqstate>0){
			      		   		ss="迟到";
			      		   }else{
			      		   		ss="正常";
			      		   }
			      		   

	 			      		if(item.qteachermsg==1){
	 			      		  	ss="缺勤";
	 			      		}
 			      		  var newTime = new Date(item.qdate); //就得到普通的时间了
	 			      		  var n=	newTime.getFullYear()+"-";
	 			      		  var y=	newTime.getMonth()+1+"-";   
	 			      		  var r=	newTime.getDate();  
	 			      		  $("#tableData").after(" <tr> <td> "+ (n+y+r) +" </td> <td> "+item.qstarttime1+" </td> <td> "+item.qtime1+" </td> <td> "+ ss +" </td> </tr> ");
 			      		 
 			      	});
 			     }
		  });      
		//并把数据进行解析
	
	
		$("#div_ckkq").fadeIn(500);
	});
});

$("#btn4").click(function() {
	$("#btnDiv").fadeOut(500, function() {
		$("#div_xgxx").fadeIn(500);
	});
});
var msg='<%=request.getAttribute("msg")%>'; 
if(msg!='null'){//如果有消息
	alert(msg);
}

</script>
</body>
</html>